import supe from '../super.js';

export default class extends supe {

    render() {
        this.node.html(`
        <h1>添加学生</h1>
        <hr/>
    <form class="layui-form">
        <div class="layui-form-item">
            <label class="layui-form-label">姓名</label>
            <div class="layui-input-inline">
                <input type="text" name="name" required lay-verify="required" placeholder="请输入姓名" autocomplete="off"
                    class="layui-input" id="stuname">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">年龄</label>
            <div class="layui-input-inline">
                <input type="text" name="age" required lay-verify="required" placeholder="请输入年龄"
                    autocomplete="off" class="layui-input" id="stuage">
            </div>
            <div class="layui-form-mid layui-word-aux">辅助文字</div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">性别</label>
            <div class="layui-input-block">
                <input type="radio" name="sex" value="男" title="男">
                <input type="radio" name="sex" value="女" title="女" checked id="stugender">
            </div>
        </div>
        <div class="layui-form-item">
            <label class="layui-form-label">地址</label>
            <div class="layui-input-inline">
                <select name="city" lay-verify="required" id="stuaddress">
                    <option disabled></option>
                    <option value="北京">北京</option>
                    <option value="上海">上海</option>
                    <option value="广州">广州</option>
                    <option value="深圳">深圳</option>
                    <option value="杭州">杭州</option>
                </select>
            </div>
        </div>
        <div class="layui-form-item">
            <div class="layui-input-block">
                <button type="button" class="layui-btn" lay-submit lay-filter="formDemo" id="addBtu">提交</button>
                <button type="reset" class="layui-btn layui-btn-primary">重置</button>
            </div>
         </div>
    </form>
        `)

    }
    handle() {
        layui.use('form', () => {
            let form = layui.form;
            form.render();
            $('#addBtu').on('click', function () {
                let gender = $('#stugender')[0].checked ? '女' : '男';
                $.ajax({
                    type: 'post',
                    url: '/student/addstu/' + $('#stuname').val() + '/' + $('#stuage').val() + '/' + gender + '/' + $('#stuaddress').val(),
                    dataType: 'json',
                    success: (data) => {
                        layer.msg(data);
                    }
                })
            })
        })
    }
}